﻿#include "module_WebOat.h"
#include <iostream>
#include <thread>
#include "module_WebOatOrm.h"
//#include "module_WebOatRedis.h"

void server_run() {
	//redis();

	//WoRefRegisterModelEx("LoginInfo",typeid(LoginInfo).name(),sizeof(LoginInfo));

	//auto reg = WoRefRegisterStruct("capt", Capt);
	//WoRefAddMember(reg, "id", Capt::ID, offsetof(Capt, ID));
	//WoRefAddMember(reg, "value", Capt::Value, offsetof(Capt, Value));

	//reg = WoRefRegisterStruct("LoginInfo", LoginInfo);
	//WoRefAddMember(reg,"username", LoginInfo::userName,offsetof(LoginInfo, userName));
	//WoRefAddMember(reg,"密码", LoginInfo::密码,offsetof(LoginInfo, 密码));
	try
	{
		WoServerClass server = WoGetAppServer();

		server.Bind("0.0.0.0", 8090);
		server.Run();
	}
	catch (...)
	{
		std::cout << "emm";
	}


}
void t_jwt() {
	auto a = []() {
		std::string lPrefix = "Bearer ";
		std::string lHander = "Authorization";
		std::string h = "Authorization: Bearer abcde";
		auto ber = h.substr(0, lPrefix.length());
		if (ber != lPrefix) {
			std::cout << "\n";
			return;
		}
		std::cout << h.substr(lPrefix.length(), h.length() - lPrefix.length()) << std::endl;
	};
	a();
	std::string r = "auth";
	auto jwt = WoJWTCreate(r.c_str());
	WoJson data;
	data["name"] = "huiyi";
	data["id"] = 12;
	WoJWTAdd(jwt, "user", data);
	std::cout << WoJWTSignHS256(jwt, "key") << std::endl;
}

int main()
{
	WoInit();
	try {

		//test_sql();
		//ref();
		//t_jwt();
		server_run();
		//sqls();
		//ref();
		//std::cout << gwttest();
	}
	catch (std::exception& err) {
		std::cout << "error:" << err.what() << std::endl;
	}
	catch (...) {
		std::rethrow_exception(std::current_exception());
	}
	WoDestroy();
	return 0;
}

